export default {
  mounted(el, binding) {
    // 复制指令
    const eventName = binding.arg || 'dblclick'
    el.addEventListener(eventName, copyToClip)

    function copyToClip() {
      const input = document.createElement('input')
      input.value = binding.value
      document.body.appendChild(input)
      input.select()
      document.execCommand('Copy')
      document.body.removeChild(input)
    }

    el._clearEvent = function () {
      el.removeEventListener(eventName, copyToClip)
    }
  },
  unmounted(el, binding) {
    // 移除指令
    el._clearEvent()
  }

}